package Utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Pattern;

public class StringUtils {
	public static String trim(String source, String reg) {
		String result = Pattern.compile(reg).matcher(source).replaceAll("");
		return result;
	}

	public static ArrayList<String> merge(ArrayList<String> list1, ArrayList<String> list2) {
		ArrayList<String> result = new ArrayList<String>();

		for (int i = 0; i < list1.size(); i++) {
			String tmp = trim(list1.get(i).trim(), "[\r" + "\n" + "\b\f|　　]");
			if (!result.contains(tmp))
				result.add(tmp);
		}

		for (int i = 0; i < list2.size(); i++) {
			String tmp = trim(list2.get(i).trim(), "[\r" + "\n" + "\b\f|　　]");
			if (!result.contains(tmp))
				result.add(tmp);
		}
		return result;
	}
	public static String inputStream2String(InputStream is) {
		BufferedReader in = new BufferedReader(new InputStreamReader(is));
		StringBuffer buffer = new StringBuffer();
		String line = "";
		try {
			while ((line = in.readLine()) != null) {
				buffer.append(line);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return buffer.toString();
	}

}
